package com.qumitech.visualnovel.controller.rest;

import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.model.common.ResultEnum;
import com.qumitech.visualnovel.controller.vo.button.ButtonConfigVO;
import com.qumitech.visualnovel.service.button.ButtonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @Author :  ZhChNing
 * @Descriptiom :
 * @Date Created in 2019/3/7 10:29
 */

@RestController
@RequestMapping(value = "/api/button")
public class ButtonController {

    @Autowired
    private ButtonService buttonService;

    @GetMapping
    public BaseRsp getButtonConfig(@RequestParam(value = "offset", defaultValue = "0") Integer offset,
                                   @RequestParam(value = "limit", defaultValue = "20") Integer limit,
                                   @RequestParam(value = "button_id", required = false) String buttonId,
                                   @RequestParam(value = "button_name", required = false) String buttonName) {
        return new BaseRsp(ResultEnum.SUCCESS, buttonService.listButtonConfigVO(offset,limit,buttonId,buttonName));
    }

    @PostMapping
    public BaseRsp addButtonConfig(@RequestBody ButtonConfigVO buttonConfigVO) {
        buttonService.addButtonConfig(buttonConfigVO);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @PutMapping(value = "/{button_id}")
    public BaseRsp updateButtonConfig(@RequestBody ButtonConfigVO buttonConfigVO, @PathVariable(name = "button_id") String buttonId) {
        buttonConfigVO.setButtonId(buttonId);
        buttonService.updateButtonConfig(buttonConfigVO);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @DeleteMapping(value = "/{button_id}")
    public BaseRsp removeButtonConfig(@PathVariable(name = "button_id") String buttonId) {
        buttonService.removeButtonConfig(buttonId);
        return new BaseRsp(ResultEnum.SUCCESS);
    }



}
